package com.zyl.pts.web.controller;

import com.zyl.pts.config.anno.SystemLog;
import com.zyl.pts.config.enums.CodeEnums;
import com.zyl.pts.config.result.Result;
import com.zyl.pts.domain.bean.Account;
import com.zyl.pts.domain.dto.AnimalDTO.AnimalUpdateOrAddDTO;
import com.zyl.pts.service.AnimalService;
import com.zyl.pts.utils.ThreadLocalUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version v1.0
 * @ProjectName: product_source
 * @Package: com.zyl.pts.web.controller
 * @ClassName: AnimalController
 * @Description TODO(动物管理模块)
 * @Author 翟玉龙
 * @Date 2024/11/20-8:47
 */
@Tag(name = "动物管理模块", description = "动物管理模块")
@RestController
@RequestMapping("/animal")
@Validated
public class AnimalController {

    private final AnimalService animalService;

    public AnimalController(AnimalService animalService) {
        this.animalService = animalService;
    }

    /**
     * 根据动物ID生成对应的二维码信息接口
     * @param animalId 动物ID
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "根据动物ID生成对应的二维码信息接口")
    @Operation(summary = "根据动物ID生成对应的二维码信息接口")
    @GetMapping("/QRcode")
    public Result<?> generateQRCode(
            @RequestParam("animalId") String animalId
    ) {
        return Result.success(
                animalService.generateQRCode(animalId)
        );
    }


    /**
     * 根据动物编号查询动物基本信息以及对应批次和栏舍栏圈信息接口
     * @param animalId 动物编号
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "根据动物编号查询动物基本信息以及对应批次和栏舍栏圈信息接口")
    @Operation(summary = "根据动物编号查询动物基本信息以及对应批次和栏舍栏圈信息接口")
    @GetMapping("/findByAnimalId")
    public Result<?> queryAnimalInfoById(
            @RequestParam("animalId") String animalId
    ) {
        return Result.success(
                CodeEnums.SUCCESS,
                animalService.queryAnimalInfoById(animalId)
        );
    }

    /**
     * 分页并根据条件查询动物基本信息以及对应批次和栏圈接口
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @param aHealthy 健康状况
     * @param aGender 性别
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "分页并根据条件查询动物基本信息以及对应批次和栏圈接口")
    @Operation(summary = "分页并根据条件查询动物基本信息以及对应批次和栏圈接口")
    @GetMapping("/query")
    public Result<?> queryAnimalInfoPage(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam(value = "aHealthy", required = false) String aHealthy,
            @RequestParam(value = "aGender", required = false) String aGender
    ) {
        System.out.println((Account) ThreadLocalUtil.get());
        return Result.success(
                CodeEnums.SUCCESS,
                animalService.queryAnimalInfoPage(pageNum, pageSize, aHealthy, aGender)
        );
    }

    /**
     * 新增或修改动物接口
     * @param animalUpdateOrAddDTO 动物信息
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "新增或修改动物接口")
    @Operation(summary = "新增或修改动物接口")
    @PostMapping("/saveOrUpdate")
    public Result<?> addOrUpdateAnimal(
            @RequestBody @Validated AnimalUpdateOrAddDTO animalUpdateOrAddDTO
    ) {
        return Result.success(
                animalService.updateOrInsertAnimal(animalUpdateOrAddDTO)
        );
    }

    /**
     * 根据ID删除动物接口
     * @param aAnimalId 动物ID
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "根据ID删除动物接口")
    @Operation(summary = "根据ID删除动物接口")
    @DeleteMapping("/deleteById/{aAnimalId}")
    public Result<?> deleteAnimalById(
            @PathVariable("aAnimalId") String aAnimalId
    ) {
        return Result.success(
                animalService.deleteAnimalById(aAnimalId)
        );
    }

    /**
     * 批量删除动物接口
     * @param aAnimalIds 动物ID列表
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "批量删除动物接口")
    @Operation(summary = "批量删除动物接口")
    @DeleteMapping("/deleteByIdAll")
    public Result<?> deleteAnimalByIds(
            @RequestBody List<String> aAnimalIds
    ) {
        return Result.success(
                animalService.deleteAnimalByIdList(aAnimalIds)
        );
    }
}
